package com.maimao.kill.controller;

import com.maimao.core.model.resp.Result;
import com.maimao.kill.controller.base.BaseController;
import com.maimao.kill.service.RequirementService;
import com.maimao.model.kill.KillRequirement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author MaoLin Wang
 * @date 2021/4/11 6:00 下午
 */
@RestController
@RequestMapping("/kill/requirement")
public class RequirementController extends BaseController {

    @Autowired
    private RequirementService requirementService;

    /**
     * 根据活动id查询约束
     * @param acId 活动id
     * @return
     */
    @GetMapping("/queryOne")
    public Result<?> queryOne(@RequestParam("acId") Integer acId) {
        KillRequirement killRequirement = requirementService.queryOne(acId);
        return Result.okData(killRequirement);
    }

    @PostMapping("/add")
    public Result<?> addRequirement(@RequestBody @Validated KillRequirement killRequirement) {
        requirementService.add(killRequirement);
        return Result.ok("添加成功");
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody @Validated KillRequirement killRequirement) {
        if (killRequirement.getId() == null) {
            return Result.notValid();
        }
        requirementService.update(killRequirement);
        return Result.ok("修改成功");
    }
}
